package com.klikmee.sms.core.commons.queues;

import java.text.MessageFormat;
import java.util.Date;

/**
 * Carries payload specified by T class type.
 * 
 * @author makcro
 * 
 */
public class QueueItem<T> {
	/**
	 * Object that carries relevant information for queue
	 */
	private T		payload;
	/**
	 * Flag indication if this item is processed or not
	 */
	private boolean	processed;

	/**
	 * This item is best used after this date. Queue processor should be aware
	 * of this info.
	 */
	private Date	validTo;

	/**
	 * Event type that should be fired when this item is discarded
	 */
	private String	discardedEventType;

	public QueueItem() {
	}

	/**
	 * @param payload
	 */
	public QueueItem(T payload) {
		super();
		this.payload = payload;
	}

	/**
	 * @param payload
	 * @param validTo
	 */
	public QueueItem(T payload, Date validTo) {
		super();
		this.payload = payload;
		this.validTo = validTo;
	}

	public T getPayload() {
		return payload;
	}

	public void setPayload(T payload) {
		this.payload = payload;
	}

	public boolean isProcessed() {
		return processed;
	}

	public void setProcessed(boolean processed) {
		this.processed = processed;
	}

	public Date getValidTo() {
		return validTo;
	}

	public void setValidTo(Date validTo) {
		this.validTo = validTo;
	}

	public String getDiscardedEventType() {
		return discardedEventType;
	}

	public void setDiscardedEventType(String discardedEventType) {
		this.discardedEventType = discardedEventType;
	}

	@Override
	public String toString() {

		return MessageFormat.format( "QueueItem, type {0}[{1}]", payload.getClass(), payload.toString() );
	}

}
